package com.pengweiwei.androidzygote.functions;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.viewpager.widget.ViewPager;

import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter;
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems;
import com.pengweiwei.androidzygote.R;
import com.pengweiwei.androidzygote.functions.base.MyListFragment;
import com.putong35.common.baseactfrag.activity.BaseActivity;

import butterknife.BindView;


/**
 * Created by yafenchen on 2017/4/15.
 */

public class TabActivity extends BaseActivity {

    @BindView(R.id.tabLayout)
    SmartTabLayout tabLayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    public static final String KEY_STATUS = "Key_Status";

    private void initView() {
        Bundle allBundle = new Bundle();
        allBundle.putInt(KEY_STATUS, 1);
        Bundle bundle1 = new Bundle();
        bundle1.putInt(KEY_STATUS, 2);
        Bundle bundle2 = new Bundle();
        bundle2.putInt(KEY_STATUS, 3);

        viewpager.setOffscreenPageLimit(1);

        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), FragmentPagerItems.with(this)
                .add("全部", MyListFragment.class, allBundle)
                .add("评价", MyListFragment.class, bundle1)
                .add("关注", MyListFragment.class, bundle2)
                .create());

        viewpager.setAdapter(adapter);
        tabLayout.setViewPager(viewpager);
    }

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, TabActivity.class);
        activity.startActivity(intent);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_tab, null);
    }

    private void setCommentTabTitle(int title) {
        String commentTitle = "评价（" + title + "）";
        View tabView = tabLayout.getTabAt(1);
        if (tabView instanceof TextView) {
            TextView textView = (TextView) tabView;
            textView.setText(commentTitle);
        }

    }

}
